package com.sywb.chuangyebao.view;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.contract.FriendsContract;
import com.sywb.chuangyebao.widget.ColorTrackTabLayout;

import butterknife.BindView;
import butterknife.OnClick;

public class UserFriendsActivity extends ActionbarActivity<FriendsContract.Presenter> implements FriendsContract.FriendView {

    @BindView(R.id.tl_index)
    ColorTrackTabLayout tlIndex;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
    @BindView(R.id.iv_search)
    ImageView ivSearch;

    private String title;

    private int type;//0关注 粉丝 话题 1已回答 待回答 3推荐 好友
    private int question_id;

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.activity_user_friends;
    }

    @Override
    public void initView(Bundle bundle) {
        super.initView(bundle);
        if (bundle == null) {
            type = getIntent().getIntExtra("p0", 0);
            question_id = getIntent().getIntExtra("p1", 0);
        } else {
            type = bundle.getInt("p0");
            question_id = bundle.getInt("p1");
        }

        switch (type) {
            case 0:
                title = "关注(好友/粉丝/话题)";
                break;
            case 1:
                title = "我的回答(已/待回答)";
                break;
            case 3:
                title = "邀请回答(推荐/好友)";
                ivSearch.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
        mPresenter.initTabView(type, viewPager, tlIndex);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putInt("p0", type);
    }

    @Override
    public String getStatisticsIdentity() {
        return title;
    }

    @OnClick({R.id.iv_back, R.id.iv_search})
    public void onClick(View view) {
        if (!isCanClick(view)) return;
        switch (view.getId()) {
            case R.id.iv_back:
                exit();
                break;
            case R.id.iv_search:
                advance(SearchPeopleActivity.class);
                break;
        }
    }

    @Override
    public int getQuestionId() {
        return question_id;
    }

}
